/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.templates.subsystems.NewPIDLifterSubsystem;

/**
 *
 * @author matt
 */
public class HighClearance extends CommandBase {

    private boolean engageHC = false;
    private boolean m_isRunning = false;
    private static int rightRearLifterPosition;
    private static int rightForeLifterPosition;
    private static int leftRearLifterPosition;
    private static int leftForeLifterPosition;

    public HighClearance(boolean HighClearanceEngage) {
        // Use requires() here to declare subsystem dependencies
        requires(leftForeLifterSubsystem);
        requires(leftRearLifterSubsystem);
        requires(rightForeLifterSubsystem);
        requires(rightRearLifterSubsystem);

        engageHC = HighClearanceEngage;

        rightRearLifterPosition = rightRearLifterSubsystem.getLifterPosition();
        rightForeLifterPosition = rightForeLifterSubsystem.getLifterPosition();
        leftRearLifterPosition = leftRearLifterSubsystem.getLifterPosition();
        leftForeLifterPosition = leftForeLifterSubsystem.getLifterPosition();

        System.out.println("HighClearance constructed - Engage = " + engageHC);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        m_isRunning = true;
        if (engageHC) {   // Engage the HC mode
            System.out.println("HC Engage");
            // Save the original positon
            rightRearLifterPosition = rightRearLifterSubsystem.getLifterPosition();
            rightForeLifterPosition = rightForeLifterSubsystem.getLifterPosition();
            leftRearLifterPosition = leftRearLifterSubsystem.getLifterPosition();
            leftForeLifterPosition = leftForeLifterSubsystem.getLifterPosition();

            // Set for High Clearnaance
            rightRearLifterSubsystem.setLifterPosition(NewPIDLifterSubsystem.LifterPresetLocation.kHighClearance);
            rightForeLifterSubsystem.setLifterPosition(NewPIDLifterSubsystem.LifterPresetLocation.kHighClearance);
            leftRearLifterSubsystem.setLifterPosition(NewPIDLifterSubsystem.LifterPresetLocation.kHighClearance);
            leftForeLifterSubsystem.setLifterPosition(NewPIDLifterSubsystem.LifterPresetLocation.kHighClearance);
        } else {          // Disengage the HC mode
            // Set back to the original position
            System.out.println("HC Release");
            rightRearLifterSubsystem.setLifterPosition(rightRearLifterPosition);
            rightForeLifterSubsystem.setLifterPosition(rightForeLifterPosition);
            leftRearLifterSubsystem.setLifterPosition(leftRearLifterPosition);
            leftForeLifterSubsystem.setLifterPosition(leftForeLifterPosition);
        }
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        m_isRunning = true;
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return m_isRunning;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }
}
